<template>
  <div class="purchase-order">
    <div class="search-condition">
      <el-form label-width="120px">
        <el-form-item label="操作人：">
          <el-input
            v-model="userName"
            placeholder="请输入内容"
          ></el-input>
        </el-form-item>
        <el-form-item label="类型："></el-form-item>
        <el-select v-model="typeValue" placeholder="请选择">
          <el-option
            key="请选择"
            label="请选择"
            value=""></el-option>
          <el-option
            v-for="item in typeOptions"
            :key="item"
            :label="item"
            :value="item">
          </el-option>
        </el-select>
        <el-form-item label="描述：">
          <el-input
            v-model="description"
            placeholder="请输入内容"
          ></el-input>
        </el-form-item>
        <el-form-item label="结果：">
          <el-input
            v-model="result"
            placeholder="请输入内容"
          ></el-input>
        </el-form-item>
        <el-form-item label-width="50px">
          <el-button type="primary" @click="pageNav(1,5)">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table
          :data="tableData"
          border
          style="width: 100%"
      >
      <el-table-column label="序号" width="100">
          <template slot-scope="scope">
        {{ (currentPage - 1) * pageSize + scope.$index + 1 }}
      </template>
      </el-table-column>
      <el-table-column prop="userName" label="操作人" width="100">
      </el-table-column>
      <el-table-column prop="type" label="类型" width="120">
      </el-table-column>
      <el-table-column prop="model" label="模块" width="200"> 
      </el-table-column>
      <el-table-column prop="description" label="描述" width="250">
      </el-table-column>
      <el-table-column prop="result" label="结果" width="280">
      </el-table-column>
      <el-table-column prop="createDate" label="操作时间" width="220">
      </el-table-column>
      <el-table-column label="操作">
      <template v-slot="scope">
          <el-button
            size="mini"
            type="danger"
            @click="handleView(scope.$index, scope.row)">查看</el-button>
          <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.$index, scope.row)">删除</el-button>
      </template>
      </el-table-column>
  </el-table>
    <div class="block">
      <el-pagination
      background
      layout="prev, pager, next"
      :total="total"
      :current-page.sync="currentPage"
      :page-size="pageSize"
      @current-change="handleCurrentChange">
      </el-pagination>
    </div>
    <el-dialog :visible.sync="logView" width="600px" append-to-body>
      <el-form ref="form" :model="form" label-width="120px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="模块：" prop="model">
              {{ form.model }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="方法名：" prop="method">
              {{ form.method }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="类型：" prop="type">
              {{ form.type }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="参数：" prop="params">
              {{ form.params }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="操作人：" prop="userName">
              {{ form.userName }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="操作时间：" prop="createDate">
              {{ form.createDate }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="操作结果：" prop="result">
              {{ form.result }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="描述：" prop="description">
              {{ form.description }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="请求地址：" prop="url">
              {{ form.url }}
            </el-form-item>
          </el-col>
        </el-row>
        
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>
  
  <script>
export default {
  name: "logManage",
  data() {
    return {
      input: "",
      tableData: [],
      total:0,
      currentPage:1,
      pageSize:5,
      logView:false,
      form:{},
      typeOptions:["新增","修改","删除","授权","导入","导出","清空数据","审核","其他"],
      typeValue:"",
      userName:"",
      description:"",
      result:""
    };
  },
  methods:{
      handleView(index, row) {
        this.logView = true;
        this.form = row;
      },
      cancel(){
        this.logView = false;
      },
      handleDelete(index, row) {
          this.$confirm("此操作将永久删除该记录, 是否继续?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }).then(() => {
            console.log(index, row);
            console.log(row.id);
            this.$http({
              url: "http://localhost:8086/delLogById",
              method: "post",
              params: {
                  id: row.id
              },
            }).then((response) => {
              console.log(response.data);
                  if (response.data.code == "200") {
                    this.pageNav(this.currentPage,5);
                      this.$message({
                      type: "success",
                      message: "删除成功!",
                      });
                  }else{
                      this.$message({
                      type: "error",
                      message: response.data.msg,
                      })
                  }
              this.pageNav(this.currentPage,5);
            }).catch((err) => {
              console.log(err);
            });
          }).catch(() => {
            this.$message({
              type: "info",
              message: "已取消删除",
            });
          });
      },
      pageNav(pageNum,pageSize){
          this.$http({
              url:"http://localhost:8086/queryLogByPage",
              method:"post",
              params:{
                  pageSize,
                  pageNum,
                  unitName:this.input,
                  type:this.typeValue,
                  userName:this.userName,
                  description:this.description,
                  result:this.result
              }
          }).then((response) => {
              this.tableData = response.data.data.list;
              this.total = response.data.data.total;
              this.currentPage = pageNum;
          }).catch((err) => {
              console.log(err);
          });
      },
      handleCurrentChange(currentPage) {
          this.pageNav(currentPage,5);
      },
  },
  mounted() {
      this.pageNav(1,5);
  }
};
</script>
  
<style>
.search-condition {
  display: flex;
  margin: 10px 0;
}
.search-condition > form {
  display: flex;
}
.search-condition input {
  width: 200px;
}
.block{
  text-align: right;
 
}
</style>
  